/**
 * 
 */
package com.rpg.base.flyweight;

import java.util.ArrayList;

import com.dalonedrau.jogl.engine.GameApplet;
import com.dalonedrau.jogl.engine.Interactive;
import com.dalonedrau.watchable.Watchable;
import com.dalonedrau.watchable.Watcher;
import com.rpg.base.globals.IOGlobals;
import com.rpg.base.globals.RPGGlobals;
import com.rpg.base.interactive.flyweight.InteractiveObject;

/**
 * @author Donald
 */
public abstract class RPGItem extends InteractiveObject implements Watchable {
	/** the item data. */
	private IOItemData	itemData;
	/**
	 * the list of {@link Watcher}s associated with this {@link IOPCData}.
	 */
	private ArrayList<Watcher>			watchers	= new ArrayList<Watcher>();
	/** Creates a new instance of {@link RPGItem}. */
	protected RPGItem() {
		super(Interactive.getInstance().getNextId());
		try {
			Interactive.getInstance().addIO(this);
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
		super.addIOFlag(RPGGlobals.IO_02_ITEM);
		init();
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void addWatcher(final Watcher watcher) {
		watchers.add(watcher);
	}
	/**
	 * Gets the item data.
	 * @return {@link IOItemData}
	 */
	public IOItemData getItemData() {
		return itemData;
	}
	/** Initializes the system specific characteristics. */
	protected abstract void init();
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void notifyWatchers() {
		for (int i = 0; i < watchers.size(); i++) {
			watchers.get(i).watchUpdated(this);
		}
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void removeWatcher(final Watcher watcher) {
		watchers.remove(watcher);
	}
	/**
	 * Sets the itemData
	 * @param val the val to set
	 */
	public void setItemData(final IOItemData val) {
		itemData = val;
	}
}
